package com.example.coursedesign.entity;

import android.os.Parcel;
import android.os.Parcelable;

import java.time.LocalDateTime;

public class User implements Parcelable {
    private int id;
    private String account;
    private String name;
    private String password;
    private String gender;
    private String role;
    private String avatar;
    private String phone;
    private String create_by;
    private LocalDateTime create_time;
    private String update_by;
    private LocalDateTime update_time;

    public User() {
    }

    public User(int id, String account, String name, String password, String gender, String role, String avatar, String phone, String create_by, LocalDateTime create_time, String update_by, LocalDateTime update_time) {
        this.id = id;
        this.account = account;
        this.name = name;
        this.password = password;
        this.gender = gender;
        this.role = role;
        this.avatar = avatar;
        this.phone = phone;
        this.create_by = create_by;
//        this.create_time = create_time;
//        this.update_by = update_by;
//        this.update_time = update_time;
    }

    // 默认构造函数，用于反序列化
    protected User(Parcel in) {
        id = in.readInt();
        account = in.readString();
        name = in.readString();
        password = in.readString();
        gender = in.readString();
        role = in.readString();
        avatar = in.readString();
        phone = in.readString();
        create_by = in.readString();
       // String createTimeStr = in.readString();
//        if (createTimeStr != null && !createTimeStr.isEmpty()) {
//            create_time = LocalDateTime.parse(createTimeStr, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
//        }
//        update_by = in.readString();
//        String updateTimeStr = in.readString();
//        if (updateTimeStr != null && !updateTimeStr.isEmpty()) {
//            update_time = LocalDateTime.parse(updateTimeStr, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
//        }
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getCreate_by() {
        return create_by;
    }

    public void setCreate_by(String create_by) {
        this.create_by = create_by;
    }

    public LocalDateTime getCreate_time() {
        return create_time;
    }

    public void setCreate_time(LocalDateTime create_time) {
        this.create_time = create_time;
    }

    public String getUpdate_by() {
        return update_by;
    }

    public void setUpdate_by(String update_by) {
        this.update_by = update_by;
    }

    public LocalDateTime getUpdate_time() {
        return update_time;
    }

    public void setUpdate_time(LocalDateTime update_time) {
        this.update_time = update_time;
    }

    // Parcelable 实现
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(id);
        dest.writeString(account);
        dest.writeString(name);
        dest.writeString(password);
        dest.writeString(gender);
        dest.writeString(role);
        dest.writeString(avatar);
        dest.writeString(phone);
        dest.writeString(create_by);
//        if (create_time != null) {
//            dest.writeString(create_time.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
//        } else {
//            dest.writeString(null);
//        }
//        dest.writeString(update_by);
//        if (update_time != null) {
//            dest.writeString(update_time.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
//        } else {
//            dest.writeString(null);
//        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<User> CREATOR = new Creator<User>() {
        @Override
        public User createFromParcel(Parcel in) {
            return new User(in);
        }

        @Override
        public User[] newArray(int size) {
            return new User[size];
        }
    };

}